package com.qf;

import com.qf.pojo.IdCard;
import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Create by 周志豪 on 2022/8/26  17:30
 *
 * @authoe 周志豪
 * @veision 1.0
 * //TODO  想好了再去做
 * @since 1.0
 */
public class test01 {

    @Test
    public void testDi(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext2.xml");

        UserService bean = (UserServiceImpl) context.getBean("userService");

        bean.adduser();

        //单例模式时init方法只会执行一次，因为都是同一个对象
        UserService bean2 = (UserServiceImpl) context.getBean("userService");

        bean.adduser();

        //已经改为多例模式
        System.out.println();
        System.out.println(bean);
        System.out.println(bean2);

        //多例对象不会执行销毁方法
        context.close();

    }

    @Test
    public void testUser(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext2.xml");

        User bean = (User) context.getBean("user");

        System.out.println(bean);
    }
    @Test
    public void testIdCard(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext2.xml");

        IdCard bean = (IdCard) context.getBean("idcard");

        System.out.println(bean);

    }
}
